<%--
  Created by IntelliJ IDEA.
  User: 任旭旺
  Date: 2020/6/1
  Time: 9:56
  To change this template use File | Settings | File Templates.
--%>
<%--
    此页面为假期申请页面
--%>

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <c:set var="request" value="${pageContext.request.contextPath}"/>
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${request}/static/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${request}/static/plugins/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-col-md4">
                    <div style="font-size: 20px;color: #009688;">
                        本年还可以请假:${sessionScope.user.vacation}天
                    </div>
                </div>

            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-list" data-type="add">请假</button>
            </div>
            <table id="vacationList" lay-filter="LAY-app-content-comm"></table>
            <div style="padding-bottom: 10px;margin-top: 10px">
                <button class="layui-btn layuiadmin-btn-list" data-type="history">请假记录</button>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="titleTpl">
    {{#  if(d.id < 100){ }}
    <a href="/detail/{{d.id}}" class="layui-table-link">{{d.title}}</a>
    {{#  } else { }}
    {{d.title}}(普通用户)
    {{#  } }}
</script>
<script src="${request}/static/plugins/layuiadmin/layui/layui.js" charset="UTF-8"></script>
<script>
    layui.config({
        base: '${request}/static/plugins/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'contlist', 'table', 'laypage'], function () {
        var $ = layui.$
            , admin = layui.admin
            , form = layui.form
            , table = layui.table
            , laypage = layui.laypage;

        //方法级渲染
        table.render({
            elem: '#vacationList'
            , url: '${request}/vacation/vacationList.html' //向后端默认传page和limit
            , cols: [[
                {type: 'numbers', fixed: 'left'}
                , {field: 'vacationName', title: '假期名'}
                , {field: 'vacationBegin', title: '假期开始时间'}
                , {field: 'vacationEnd', title: '假期结束时间'}
                , {field: 'officialVacation', title: ' 是否法定假期',templet: function(officialVacation){
                        if(officialVacation==0) return "不是";
                        else return "是"
                    }}
            ]]
            , page: true
            , limit: 10
            , limits: [5, 10, 15, 20]
            , id: 'vacationList'
            , request: {
                pageName: 'pageNum',
                limitName: 'pageSize'  //如不配置，默认为page=1&limit=10
            }
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            }

        });



        var $ = layui.$, active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '请假'
                    , content: '${request}/vacation/applyVacationForm.html'
                    , maxmin: true
                    , area: ['820px', '800px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");

                        iframeWindow.layui.form.on('submit(layuiadmin-app-form-submit)', function (data) {
                            var field = data.field; //获取提交的字段

                            // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            var json = {
                                empId: ${sessionScope.user.id}
                                , beginTime: field.beginTime
                                , endTime: field.endTime
                                , reason: field.reason
                            };
                            console.log(json);
                            //提交 Ajax 成功后，关闭当前弹层并重载表格
                            $.ajax({
                                data: json,
                                type: 'post',
                                url: "${request}/vacation/insertEmpVacation.html",
                                success: function (res) {
                                    if (res.code == 100) {
                                        layer.msg('申请成功', {
                                            icon: 1
                                            , time: 1000
                                        });

                                        layer.close(index); //再执行关闭

                                    } else {
                                        return layer.msg('未知错误');
                                    }
                                }
                            });

                        });
                        submit.trigger('click');
                    }
                });
            },
            history:function () {
                layer.open({
                    type: 2
                    , title: '请假记录'
                    , content: '${request}/vacation/applyVacationHistory.html'
                    , maxmin: true
                    , area: ['1000px', '800px']
                    , btn: ['确定', '取消']

                });

            }
        };


        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });




    });
</script>
</body>
</html>


